#include "../NewSyndrome-module.h"
#include "admin-public.h"


void module_init (void)
{
	bot_set_auteur_module ("Thaeron");
	bot_set_desc_module ("Pour mettre et retirer le bot des salons");
	bot_set_ident_module ("joinpart");
	bot_set_version_module ("0.2");
	
	bot_add_cmd_handler ("join", "join_it");
	bot_add_cmd_handler ("part", "part_it");
}


void init_dep (char *nom, void *addr)
{
	static byte mut = 0;
	if (!mut++)
		admin_is_admin = NULL;

	if (!strcmp (nom, "admin_is_admin"))
		admin_is_admin = (void *) addr;

#ifdef WIN32
	init_share_dep (nom, addr);
#endif
}


int join_it (msg * i)
{	
	if ((!is_botnick (i->dest)) || (i->nbarg < 2) || (admin_is_admin (i->sender) < 800))
		return (0);

	bot_send_rawf ("JOIN %s\n", i->argu[1]);

	return (0);
}


int part_it (msg * i)
{
	char *msg;
	
	if ((!is_botnick (i->dest)) || (i->nbarg < 2) || (admin_is_admin (i->sender) < 800))
		return (0);

	if (i->nbarg == 2)
		bot_send_rawf ("PART %s\n", i->argu[1]);
	else
	{
		msg = argu_to_string (i->argu, i->nbarg, NULL, 2);
		bot_send_rawf ("PART %s :%s\n", i->argu[1], msg);
		free (msg);
	}	

	return (0);
}
